package com.ctsi.framework.mybatis.dialect;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 
 */
public class FbDialect extends AbstractMiDialect {

 

	@Override
	public void setLimitParamters(PreparedStatement ps, int parameterSize, int offset, int limit) throws SQLException {
		if(offset > 0){
			ps.setInt(parameterSize + 1, offset);
			ps.setInt(parameterSize + 2, limit);
		}else{
			ps.setInt(parameterSize + 1, limit);
		}

	}

	@Override
	public String getLimitString(String sql, int offset) {

		return new StringBuilder( sql.length()+20 )
				.append(sql)
				.append(  offset>0 ? " OFFSET ? ROWS FETCH FIRST ? ROWS ONLY " : " FETCH  FIRST ? ROWS ONLY ")
				.toString();
	}

	@Override
	public boolean supportsLimitOffset() {

		return true;
	}
 
}
